package com.andreams.restaurant.webservice;

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;

import com.andreams.restaurant.domain.Restaurant;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;


@Provider
public class MyJAXBContextResolver implements ContextResolver<JAXBContext> {

    private JAXBContext context;
    private Class[] types = {Restaurant.class};
    
    public MyJAXBContextResolver() throws Exception {
        this.context = new JSONJAXBContext(
                JSONConfiguration.natural().build(),
                types);
    }
    
	@Override
	public JAXBContext getContext(Class<?> arg0) {
		return (types[0].equals(arg0)) ? context : null;
	}

}
